package uic.easyface;

import android.app.Activity;
import android.content.Intent;
import android.graphics.Bitmap;
import android.os.Bundle;
import android.view.View;
import android.widget.AdapterView;
import android.widget.AdapterView.OnItemClickListener;

import android.graphics.drawable.BitmapDrawable;
import android.view.View.OnClickListener;
import android.widget.Button;
import android.widget.Toast;

public class ChoosePage extends Activity {

	private FaceDetectorAndMarker fdam;
	private Bitmap add = null;
	private Button exit;

	public void onCreate(Bundle savedInstanceState) {
		fdam = (FaceDetectorAndMarker) getApplication();
		super.onCreate(savedInstanceState);
		Toast.makeText(this, R.string.choose, Toast.LENGTH_SHORT).show();
		setContentView(R.layout.choose);

		Integer[] images = { R.drawable.img1, R.drawable.img2, R.drawable.img3,
				R.drawable.img4, R.drawable.img5, R.drawable.img6,
				R.drawable.img7, R.drawable.img8, R.drawable.img9,
				R.drawable.img10 };

		final ImageAdapter adapter = new ImageAdapter(this, images);
		adapter.createReflectedImages();

		final GalleryFlow galleryFlow = (GalleryFlow) findViewById(R.id.Gallery01);
		galleryFlow.setAdapter(adapter);
		galleryFlow.setOnItemClickListener(new OnItemClickListener() {
			public void onItemClick(AdapterView<?> arg0, View arg1, int arg8,
					long arg3) {
				// TODO Auto-generated method stub
				if (arg8 == 0) {
					add = ((BitmapDrawable) getResources().getDrawable(
							R.drawable.img1)).getBitmap();
					Intent it = new Intent();

					it.setClass(ChoosePage.this, MainActivity.class);

					startActivity(it);
				} else if (arg8 == 1) {
					add = ((BitmapDrawable) getResources().getDrawable(
							R.drawable.img2)).getBitmap();
					Intent it = new Intent();

					it.setClass(ChoosePage.this, MainActivity.class);

					startActivity(it);
				} else if (arg8 == 2) {
					add = ((BitmapDrawable) getResources().getDrawable(
							R.drawable.img3)).getBitmap();
					Intent it = new Intent();

					it.setClass(ChoosePage.this, MainActivity.class);

					startActivity(it);
				} else if (arg8 == 3) {
					add = ((BitmapDrawable) getResources().getDrawable(
							R.drawable.img4)).getBitmap();
					Intent it = new Intent();

					it.setClass(ChoosePage.this, MainActivity.class);

					startActivity(it);
				} else if (arg8 == 4) {
					add = ((BitmapDrawable) getResources().getDrawable(
							R.drawable.img5)).getBitmap();
					Intent it = new Intent();

					it.setClass(ChoosePage.this, MainActivity.class);

					startActivity(it);
				} else if (arg8 == 5) {
					add = ((BitmapDrawable) getResources().getDrawable(
							R.drawable.img6)).getBitmap();
					Intent it = new Intent();

					it.setClass(ChoosePage.this, MainActivity.class);

					startActivity(it);
				} else if (arg8 == 6) {
					add = ((BitmapDrawable) getResources().getDrawable(
							R.drawable.img7)).getBitmap();
					Intent it = new Intent();

					it.setClass(ChoosePage.this, MainActivity.class);

					startActivity(it);
				} else if (arg8 == 7) {
					add = ((BitmapDrawable) getResources().getDrawable(
							R.drawable.img8)).getBitmap();
					Intent it = new Intent();

					it.setClass(ChoosePage.this, MainActivity.class);

					startActivity(it);
				} else if (arg8 == 8) {
					add = ((BitmapDrawable) getResources().getDrawable(
							R.drawable.img9)).getBitmap();
					Intent it = new Intent();

					it.setClass(ChoosePage.this, MainActivity.class);

					startActivity(it);
				} else {
					add = ((BitmapDrawable) getResources().getDrawable(
							R.drawable.img10)).getBitmap();
					Intent it = new Intent();

					it.setClass(ChoosePage.this, MainActivity.class);

					startActivity(it);
				}

				fdam.setAddOn(add);
			}
		});

		exit = (Button) this.findViewById(R.id.bt);
		exit.setOnClickListener(exitclick);

	}

	OnClickListener exitclick = new OnClickListener() {

		public void onClick(View arg0) {

			finish();

		}

	};
}
